import java.util.Scanner;
import java.util.*;

public class MC0341与7无关数 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        // code here
        int n = input.nextInt();
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            if (!aBoolean(i)){
                sum += i;
            }
        }
        System.out.println(sum);
        input.close();
    }

    public static boolean aBoolean(int n) {
        if (n % 7 == 0) {
            return true;
        }
        int temp = n;
        while(temp > 0){
            if(temp % 10 == 7){
                return true;
            }
            temp /= 10;
        }
        return false;
    }
}
